package com.open.pokergames.biz.viewModel;

import com.open.pokergames.NetConfig
import com.open.pokergames.base.entity.AppPageData
import com.open.pokergames.base.entity.PageReq
import com.open.pokergames.biz.entity.*
import com.open.pokergames.comm.repository.Api
import com.open.pokergames.comm.repository.entity.ResultCode
import com.open.pokergames.comm.repository.entity.ResultInfo
import com.open.pokergames.texas.repository.entity.RoomEntity
import com.sinothk.rxretrofit.RxRetrofit
import org.greenrobot.eventbus.EventBus
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers


class BizViewModel {
//
//    fun login(loginVo: LoginVo) {
//
//        RxRetrofit.init(NetConfig.BASE_URL)//, ServerConfig.getHeader()
//            .create(Api::class.java)
//            .login(loginVo)
//            .subscribeOn(Schedulers.io())
//            .observeOn(AndroidSchedulers.mainThread())
//            .subscribe(object : Subscriber<ResultInfo<LoginDto>>() {
//
//                override fun onCompleted() {}
//
//                override fun onError(e: Throwable) {
//                    val result = ResultInfo<ResultInfo<LoginDto>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
//                    result.eventType = "login"
//                    EventBus.getDefault().post(result)
//                }
//
//                override fun onNext(result: ResultInfo<LoginDto>) {
//                    result.eventType = "login"
//                    EventBus.getDefault().post(result)
//                }
//            })
//    }
//
//    fun register(userVo: UserVo) {
//        RxRetrofit.init(NetConfig.BASE_URL)//, ServerConfig.getHeader()
//            .create(Api::class.java)
//            .register(userVo)
//            .subscribeOn(Schedulers.io())
//            .observeOn(AndroidSchedulers.mainThread())
//            .subscribe(object : Subscriber<ResultInfo<LoginDto>>() {
//
//                override fun onCompleted() {}
//
//                override fun onError(e: Throwable) {
//                    val result = ResultInfo<ResultInfo<LoginDto>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
//                    result.eventType = "register"
//                    EventBus.getDefault().post(result)
//                }
//
//                override fun onNext(result: ResultInfo<LoginDto>) {
//                    result.eventType = "register"
//                    EventBus.getDefault().post(result)
//                }
//            })
//    }

    fun getMyGroups(pageReq: PageReq<GroupEntity>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())//
            .create(Api::class.java)
            .getMyGroups(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<GroupEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<GroupEntity>>(
                        ResultInfo.ERROR,
                        ResultInfo.getErrorMsg(e.message)
                    )
                    result.eventType = "getMyGroups"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<GroupEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "getMyGroups"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun roomsForUserJoinGroup(pageReq: PageReq<RoomVo>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .roomsForUserJoinGroup(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<RoomEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<RoomEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "roomsForUserJoinGroup"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<RoomEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "roomsForUserJoinGroup"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun page7CardsForGroupMember(pageReq: PageReq<RoomVo>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .page7CardsForGroupMember(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<RoomEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<RoomEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "roomsForUserJoinGroup"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<RoomEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "roomsForUserJoinGroup"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun roomsForGroup(pageReq: PageReq<RoomVo>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .roomsForGroup(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<RoomEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<RoomEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "roomsForGroup"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<RoomEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "roomsForGroup"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun addGroup(groupVo: GroupVo) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .addGroup(groupVo)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<String>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<String>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "addGroup"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<String>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "addGroup"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun msgForGroup(pageReq: PageReq<GroupMessageEntity>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .msgForGroup(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<GroupMessageEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<GroupMessageEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "msgForGroup"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<GroupMessageEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "msgForGroup"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun roomAdd(room: RoomEntity) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .roomAdd(room)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<RoomEntity>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<RoomEntity>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    if (room.roomType == 0) {
                        result.eventType = "roomAdd"
                    } else if (room.roomType == 1) {
                        result.eventType = "roomAdd7"
                    }
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<RoomEntity>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        if (room.roomType == 0) {
                            result.eventType = "roomAdd"
                        } else if (room.roomType == 1) {
                            result.eventType = "roomAdd7"
                        }
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun pageForInvite(pageReq: PageReq<InviteEntity>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .pageForInvite(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<InviteEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<InviteEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "pageForInvite"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<InviteEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "pageForInvite"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun inviteJoin(inviteId: String, state: Int) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .inviteJoin(inviteId, state)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<InviteEntity>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<InviteEntity>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "inviteJoin"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<InviteEntity>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "inviteJoin"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun groupDetail(groupId: String) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .groupDetail(groupId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<GroupDto>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<GroupDto>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "groupDetail"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<GroupDto>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "groupDetail"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun inviteExit(bizId: String, bizType: String) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .inviteExit(bizId, bizType)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<String>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<String>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "inviteExit"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<String>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "inviteExit"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun pageForGroupMember(pageReq: PageReq<GroupMemberListEntity>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .pageForGroupMember(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<GroupMemberListEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<GroupMemberListEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "pageForGroupMember"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<GroupMemberListEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "pageForGroupMember"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun searchUserByKeywords(pageReq: PageReq<MemberVo>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .searchUserByKeywords(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<MemberEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<MemberEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "searchUser"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<MemberEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "searchUser"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun inviteAdd(groupId: String?, toAccount: String?) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .inviteAdd(groupId, toAccount)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<String>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<String>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "inviteAdd"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<String>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "inviteAdd"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun pageForRoomCardLog(pageReq: PageReq<RoomCardLogEntity>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .pageForRoomCardLog(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<RoomCardLogEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<RoomCardLogEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "pageForRoomCardLog"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<RoomCardLogEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "pageForRoomCardLog"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun addRoomCardAdd(getId: String?, value: String) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .addRoomCardAdd(getId, value)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<String>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<String>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "addRoomCardAdd"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<String>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "addRoomCardAdd"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun pageForGroupCoinLog(pageReq: PageReq<GroupCoinsLogEntity>) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .pageForGroupCoinLog(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<GroupCoinsLogEntity>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<GroupCoinsLogEntity>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "pageForGroupCoinLog"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<GroupCoinsLogEntity>>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "pageForGroupCoinLog"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun optGroupCoin(vo: GroupCoinsVo) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .optGroupCoin(vo)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<String>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<String>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "optGroupCoin"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<String>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "optGroupCoin"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun retrieveRoom(roomNum: String) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .retrieveRoom(roomNum)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<RoomEntity>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<RoomEntity>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "retrieveRoom"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<RoomEntity>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "retrieveRoom"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun getGroupMemberByRoomNum(roomNum: String) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .getGroupMemberByRoomNum(roomNum)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<GroupMemberEntity>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<GroupMemberEntity>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "getGroupMemberByRoomNum"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<GroupMemberEntity>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "getGroupMemberByRoomNum"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun getShowInfo() {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .showInfo
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<ShowInfo>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<GroupMemberEntity>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "getShowInfo"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<ShowInfo>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "getShowInfo"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }

    fun setGroupPartner(groupId: String, memberAccount: String) {
        RxRetrofit.init(NetConfig.BASE_URL, NetConfig.getHeader())
            .create(Api::class.java)
            .setGroupPartner(groupId, memberAccount)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<String>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<String>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "setGroupPartner"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<String>) {
                    if (result.code == ResultCode.SYS_INVALID_SIGN.code()) {
                        result.eventType = ResultInfo.EVENT_TYPE_GLOBAL
                        EventBus.getDefault().post(result)
                    } else {
                        result.eventType = "setGroupPartner"
                        EventBus.getDefault().post(result)
                    }
                }
            })
    }
}
